home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / qbbugs.arc / QUIRKS.TXT
Text File  |  1987-12-23  |  22KB  |  454 lines

  1. New items for this release 12/23/87:
  2.  
  3. Part 1 - TYPE..END TYPE
  4. Part 2 - Long Integers
  5. Part 3 - Sample program #2
  6. -------------------------------------------------------------------------
  7.  
  8. This file contains information about bugs, quirks, and general points
  9. of interest to programmers working with compiled BASIC. It is divided
  10. into three parts:
  11.  
  12.   Part 1 - Description of bugs, quirks and errors
  13.   Part 2 - General points of interest
  14.   Part 3 - Sample programs
  15.  
  16. If you want to find one of the above quickly, use your text editor to
  17. search for the text shown above. i.e., Search for "Part 1 -".
  18.  
  19. This file was compiled by Mark Novisoff of MicroHelp, Inc. Much of the
  20. information was contributed by members of MicroHelp's BASIC Users Group.
  21. If you have additional information that should be added, please send it
  22. to:
  23.      Mark Novisoff
  24.      MicroHelp, Inc.
  25.      2220 Carlyle Drive
  26.      Marietta GA 30062
  27.      (404) 973-9272
  28.      Compuserve ID 73047,3706 in MSSYS (Microsoft Systems Forum)
  29.  
  30. Part 1 - Description of bugs, quirks and errors
  31.  
  32. Command/Error  Compilers       Description
  33. -------------- --------------- --------------------------------------------
  34. CALL (asm)     QB 4            Effective with QB 4, assembly
  35.                                language subroutines must preserve
  36.                                the SI and DI registers and make
  37.                                sure the direction flag is cleared
  38.                                before returning to BASIC.
  39. CALL INIT      QB 2-3          Do not name a precompiled subprogram "INIT".
  40.                                If you do, the compiler will go into never-
  41.                    never land when your user library is loaded.
  42. CALL vs GOSUB  All             If you have many calls to the same
  43.                                asm routine or subprogram, you'll
  44.                                use less memory if you set
  45.                                variables and GOSUB to a routine
  46.                                that performs the CALL instead of
  47.                                having the CALL "in line". CALL is
  48.                                much faster using variables than
  49.                                using "literals".
  50. CALLS          QB 4            When CALLS (note the "S") is used and you
  51.                                compile with "/D" (debug), the segment of
  52.                    of a string element descriptor does not get
  53.                    passed on the stack. In other words, if you
  54.                    have an assembly language subroutine that
  55.                    uses CALLS, you should not compile with "/d".
  56. CHAIN          QB 4            Unreliable when using DOS 2.x.
  57. CIRCLE         QB 4            The start and end angles must be
  58.                                LESS than 2*pi. Previously they could
  59.                    be less than or equal to.
  60. CLEAR,,Size    QB 3,4          If you receive an out of stack
  61.                                space message. The stack size is
  62.                                not reset between CHAIN'ing but if
  63.                                you CHAIN back to your original
  64.                                program, be sure to skip the CLEAR
  65.                                instruction.
  66. COMMON and     QB 2-4          All statements that use COMMON or variations
  67.   COMMON SHARED                thereon with CHAIN must use parameter lists
  68.                                that match exactly. Best done with $Include.
  69. COMMON with TYPE
  70.                QB 4            The TYPE statement must appear before
  71.                            the COMMON statement and must appear in
  72.                    all programs that use it. The COMMON
  73.                    statement must contain "AS". See sample
  74.                    program #1 at the end of this file.
  75. Compile to EXE QB 4            QB issues an unusual LINK command in the
  76.                                form of:
  77.                      LINK Prog+YourLib.Lib;
  78.                    This causes LINK to bring the entire
  79.                    library into your program! The solution is
  80.                    to exit QB, and run BC and LINK yourself.
  81. CONST          QB 4            Must be included in all program modules
  82.                                that use the constant. Place in the file
  83.                    at the top, rather than inside SUB's.
  84. DATA           QB 4            When a DATA statement is encountered inside
  85.                                a SUB...END SUB structure, QB moves it
  86.                    into the "mainline" portion of the code when
  87.                    you are in the environment. 
  88. DEF FN         All             Functions are local to the module
  89.                                in which the DEF FN appears. Use
  90.                                QB 4's FUNCTION..END FUNCTION for
  91.                                global functions.
  92. DIM            QB 4            Static numeric arrays are stored on the
  93.                                "heap" when you are inside the QB 4
  94.                    environment. BC programs store them in the
  95.                    default DS.
  96. DIM (TYPE)     QB 4            See sample program #1 for dimensioning
  97.                                arrays of TYPE'd variables.
  98. Division       All             Using integer division "\" when an
  99.                                integer result is desired is much
  100.                                faster than normal division "/".
  101. DRAW           QB 2-4          Does not respect the boundaries designated
  102.                                by WINDOW.
  103. FRE(-1)        QB 4            If a Quick Library is loaded, this value
  104.                                may return incorrectly. QB 4 seems to
  105.                    forget that the library is loaded and
  106.                    thinks that the space is available. But,
  107.                    QB 4 won't let you use the space for
  108.                    dynamic arrays.
  109. FRE("")        QB 4            Using BRUN gives approximately 4K more
  110.                                than BCOM.
  111. FUNCTION       QB 4            Provides global functions for all
  112.                                modules in a program. All that is
  113.                                needed is a DECLARE statement in
  114.                                any module that needs to use the
  115.                                function. In addition, this type
  116.                                of function can be recursive. See DEF FN.
  117. FUNCTION       QB 4            Cannot be used in $Include files.
  118. IF..THEN..ELSE QB 3            More than two nestings for ELSE on a single
  119.                                line will not compiler properly.
  120. HEX$           QB 4            Be careful when using with non-integer
  121.                                values. For example, the output from
  122.                    the two lines shown is "FFFF8002".
  123.                      E&=&H8002
  124.                      PRINT HEX$(E&)
  125. LINK           All             Use the /EXEPACK switch to condense the
  126.                                file. Can be used on any program except
  127.                    programs that are CHAIN'ed to using
  128.                    all compilers except QB 4. All QB 4
  129.                    programs can use this switch. Syntax:
  130.                      LINK /EXE Progname (etc.)
  131. LINK           QB 4            When building a Quick Library, be sure
  132.                                to specify BQLB40 in the library field. Example:
  133.                      LINK /QU ObjMods,Lib,,BQLB40;
  134. LOAD           QB 4            If you receive an "out of memory"
  135.                                error, try breaking your program
  136.                                into logical pieces (using
  137.                                subprograms). Then use COMMON
  138.                                SHARED for all variables that you
  139.                                need in the entire program. The
  140.                                exact same COMMON SHARED
  141.                                declaration must appear in all the
  142.                                modules in the program that need
  143.                                access to the variables.
  144. LOAD            QB 4           If you download a QB 4 program in "fast load"
  145.                                format, many modem transfer protocols
  146.                    pad the file out using a number of
  147.                    CHR$(0)'s. This will cause QB 4 to
  148.                    crash when you attempt to load the program.
  149.                    Use DEBUG to view the file, then write
  150.                    the program to disk after changing the
  151.                    CX register to shorten the length of the
  152.                    file so that the trailing CHR$(0)'s are
  153.                    not included. The other solution is to
  154.                    download this type of file using an ARC
  155.                    program that restores the original length
  156.                    of the file.
  157. ON ERROR        QB 2-4         Error handler routines must be located
  158.                                outside SUB...END SUB structures. You
  159.                    can RESUME to a line number/label that
  160.                    is outside SUB...END SUB structures 
  161.                    (using /E) or to code inside the sub
  162.                    using plain RESUME or RESUME 
  163.                    NEXT (/X). Much better is to $Include
  164.                    subroutines that perform error trapping
  165.                    instead of having them in subprograms.
  166.                    This allows the use of RESUME line number/
  167.                    label and avoids the /X.
  168. OPEN            All            With Novell NetWare, using OPEN on a file that
  169.                                does not exist does not always create the file.
  170.                    Novell has acknowledged the problem but no
  171.                    solution is available as of 12/19/87.
  172. Overflow        All            BASIC uses integer types for all
  173.                                calculations and processes the
  174.                                right side of the equal sign
  175.                                before the left side. To force
  176.                                BASIC to use a different numeric
  177.                                type, place a type identifier on
  178.                                the right of the equal sign.
  179.                                Example: A=Peek(2)+256!*Peek(3)
  180. RESUME          All            If you always use RESUME
  181.                                <linenumber> or RESUME <label> you
  182.                                can use the "/e" switch instead of
  183.                                "/x". Makes programs smaller!
  184.                                This is not practical for
  185.                                subprograms, so error trapping is
  186.                                better handled in mainline code.
  187.                    See ON ERROR.
  188. RESUME          QB 4           If you compile to an EXE from
  189.                                inside the environment, a "/X" is
  190.                                generated by QB even though it's
  191.                                not needed. Be sure to recompile
  192.                                with "/E" outside of the
  193.                                environment if your program
  194.                                doesn't need "/X".
  195. SADD            QB 4           When using SADD-188 for Btrieve,
  196.                                be sure to make this calculation
  197.                                EACH TIME you are going to CALL
  198.                                Btrieve. This is because QB 4 can
  199.                                move the FIELD'ed strings around
  200.                                in memory.
  201. SAVE            QB 4           If you edit a new program and save it,
  202.                                QB defaults to "fast load" format. The
  203.                    file cannot be handled by a text editor.
  204.                    Fix by using "save as".
  205. SELECT CASE     QB 4           Doesn't allow periods in variable names that
  206.                                are "plain" variables. If using a TYPE'd
  207.                    record element (which does indeed use periods),
  208.                    QB 4 will accept that with no problem.
  209. SIGNAL          QB 4           Keyword reserved for future use.
  210. SLEEP           QB 4           Keyword reserved for future use.
  211. SOUND           QB 3/87        Generates error 6 in all forms when the
  212.                                emulator is used on non-87 machines.
  213. STATIC          QB 4           When used with a subprogram, makes
  214.                                the subprogram faster, since local
  215.                                variables are not initialized on
  216.                                each call.
  217. String Space    QB 4           Drops you out to DOS without saving
  218.   Corrupt                      your program. The solution is to save
  219.                                often!
  220. STRING$         All            A$=String$(5,65) takes less code than
  221.                                A$=String$(5,"A") and both are smaller
  222.                    than A$="AAAAA".
  223. SUB...END SUB   QB 4           Cannot be used in $Include files. Cannot
  224.                                have the same name as a variable (regardless
  225.                    of the variable type).
  226. TYPE..END TYPE  QB 4           There has been an unverified problem reported
  227.                                in QB when the record length is an odd number.
  228.                    A "FAR HEAP CORRUPT" error is generated.
  229.                    The problem reportedly occurs when the record
  230.                    length is an odd number of bytes. It does not
  231.                    seem to appear in BC, only QB. If you have
  232.                    an unusual, otherwise unexplained problem,
  233.                    try changing the record length to an even number.
  234. TYPE..END TYPE
  235.  (with COMMON)  QB 4           See COMMON (with TYPE) and sample program #1.
  236. VAL             QB 4           Generates an error (rather than value of 0)
  237.                                when "%" is the first character in the string.
  238. WINDOW          QB 2-4         Does not affect DRAW statements.
  239. ----------------------------------------------------------------------------
  240. Part 2 - General points of interest
  241. ----------------------------------------------------------------------------
  242. Long integers with QB 4
  243.  
  244. When you have a long integer array with two dimensions, BC does not handle
  245. the zeroth elements correctly, but QB works with it OK. The fix is not to
  246. use the zeroth elements.
  247.  
  248. Secondly, if you dimension the same two-dimensional array using a variable
  249. name instead of a numeric constant, BC cannot handle your array at all! The
  250. fix is to use only constant numbers in dimensioning the array. Another fix
  251. that DOES work with dynamic arrays, is to use the /R switch when compiling.
  252. ----------------------------------------------------------------------------
  253. More on long integers
  254.  
  255. If you pass a long integer array to a subprogram, QB will work OK, but
  256. BC does not. See Sample Program #2.
  257. ----------------------------------------------------------------------------
  258. LIB environment variable
  259.  
  260. If you set the LIB environment variable, you will find that QB, BC, BUILDLIB
  261. and LINK will all search the specified path whenever a User Lib, Quick Lib or
  262. LINK lib is needed. The syntax is similar to the DOS Path syntax:
  263.  
  264.   SET LIB=C:\Libs;C:\DOS;C:\QB
  265. ----------------------------------------------------------------------------
  266. Undocumented switches in QuickBASIC 3
  267.  
  268. QB ProgramName/F compiles the specified program to an EXE file without 
  269. starting up the QB editor.
  270.  
  271. QB ProgramName/Z tells QB to load and execute ProgramName and exit to DOS
  272. when the program ends.
  273. ----------------------------------------------------------------------------
  274. Response files
  275.  
  276. BUILDLIB and LINK both accept input from response files. This is exactly the
  277. same as redirection of input, but the programs will continue running when
  278. the end of the file is reached prematurely. Example:
  279.  
  280. Response file contains:
  281.   Prog1+Prog2+Prog3+
  282.   Prog4+Prog5+Prog6 Rem Don't include ANY additional blank lines
  283.   
  284. Buildlib batch file contains:
  285.   Buildlib @Response.Fil,MyLib.Exe;
  286.   
  287. Buildlib will take its input from the response file because the "@" sign
  288. tells it to!      
  289. ----------------------------------------------------------------------------
  290. BUILDLIB and "too many segments" error
  291.  
  292. Where "nnnn" is a number from 1 to 1024, use:
  293.  
  294.    BUILDLIB /SEG:nnnn
  295.  
  296. That increases (or decreases) the number of allowable segments. Default=255.
  297. ----------------------------------------------------------------------------
  298. Patching QB 4 menu and help colors.
  299.  
  300. This color table in this file was uploaded by Dave Engfer to the 
  301. MicroHelp Basic Users Group BBS.
  302.  
  303. If you don't like the colors that QB 4.0 uses, you can patch it to show
  304. the colors you want. In order to effect your patches, do the following:
  305.  
  306.   Make a backup copy of QB.EXE.
  307.   REN QB.EXE QB <Enter>
  308.   DEBUG QB <Enter>
  309.   R <Enter>
  310.     
  311. At this point, debug will show you the current register settings and
  312. the current instruction. Something like this:
  313.  
  314. -r
  315. AX=0000  BX=0003  CX=82A0 etc.
  316. DS=xxxx  ES=xxxx  SS=xxxx etc.
  317. xxxx:0100 RD       DEC     BP
  318.  
  319. The "xxxx" is the current code segment. On my machine, the value is 2A28.
  320. The color table that QB uses is located near the end of the QB program, 
  321. specifically 3 full segments higher than "xxxx". That means you will
  322. need to add 3000 hex to the number of the segment shown. In my case,
  323. I would patch segment 5A28. Note that adding 3 to the first of the four
  324. hex numbers does the trick.
  325.  
  326. Now, with the higher segment address in mind, display the existing color
  327. table. Remember, the segment on your machine is most likely different
  328. from mine, but the offset "5B6F" should be the same. On my system:
  329.  
  330.    d 5A28:5B6F <Enter>
  331.  
  332. gives the following table (on my system, "xxxx" is 5A28):
  333.    
  334. xxxx:5B60                                              34
  335. xxxx:5B70 30 4F 34 30 38 4F 47 34-38 70 71 74 07 47 0A 30
  336. xxxx:5B80 3F 17 4A 00 07 70 70 0F-7F 70 78 0F 07 7F 70 70 etc.
  337.  
  338. Below you'll find a table of the colors and what Dave thinks they represent.
  339. Note that some are marked "unknown". Dave suspects they may be related to
  340. rodents.
  341.  
  342. You can change your copy of QB to display the various colors by changing
  343. the values in the table. The formula for determining color is the same as
  344. in Mach 2: Attribute=Background*16+Foreground.
  345.  
  346. As an example, suppose you want to change the "top line highlight" to
  347. red on green (XMAS is only a month away!). The color attribute we want
  348. (in HEX for debug) is 2*16+4 or 36 decimal or 24 HEX.
  349.  
  350. So, to patch that color:
  351.  
  352. -e xxxx:5B71 24 <Enter>
  353. -w <Enter>
  354. -q <Enter>
  355. REN QB QB.EXE
  356.  
  357. Now, when you hold the Alt key (without pressing anything else), "File"
  358. appears in red on green.
  359.  
  360.      Original Color        Addr  Byte   Effect        
  361.      ---------------------------------------------------------------------
  362.      Red on Cyan           5B6F   34    The outline for the pulldown boxes
  363.      Black on Cyan         5B70   30    The Color for the top line
  364.      Bright White on Red   5B71   4F    Top line Highlight (e.i. press 'Atl'
  365.                                         and the option will highlight)
  366.      Red on Cyan           5B72   34    Top line first letter highlight
  367.      Black on Cyan         5B73   30   *Pulldown box text and background - 1
  368.      Bright Black on Cyan  5B74   38   *Pulldown box text and background - 2 
  369.      Bright White on Red   5B75   4F   *Pulldown box highlight line - 1
  370.      White on Red          5B76   47   *Pulldown box highlight line - 2
  371.      Red on Cyan           5B77   34   *Pulldown box first letters - 1
  372.      Bright Black on Cyan  5B78   38   *Pulldown box first letters - 2
  373.      Black on White        5B79   70    Frame around the Help box- Shft F1
  374.      Blue on white         5B7A   71    Help box selection area- Shft F1
  375.      Red on White          5B7B   74    Help box first letter highlight- F1
  376.                            5B7C   07    Unknown
  377.                            5B7D   47    Unknown
  378.                            5B7E   0A    Unknown
  379.      Black on Cyan         5B7F   30    Bottom line prompt text
  380.      Bright White on Cyan  5B80   3F    Microsoft Copyright Notice  
  381.  
  382. Notes-     
  383.      * - Microsoft uses two different color bytes for the pulldown boxes.
  384.      1 - This byte seems to be used for options with a highlight letter.
  385.      2 - This byte seens to be used for options without a highlight letter.
  386. ----------------------------------------------------------------------------
  387. Part 3 - Sample programs
  388. ----------------------------------------------------------------------------
  389. Sample program #1. How to use COMMON with TYPE'd variables.
  390.  
  391.        ' Prog1.bas
  392.  
  393.          TYPE Namerec
  394.            LastName AS STRING * 20
  395.            FirstName AS STRING *15
  396.          END TYPE
  397.          COMMON Filename() AS Namerec
  398.          DIM Filename(5) AS Namerec
  399.          Filename(1).LastName="Novisoff"
  400.          Filename(1).FirstName="Mark"
  401.          CHAIN "Prog2"
  402.  
  403.        ' Prog2.bas
  404.        
  405.          TYPE Namerec
  406.            LastName AS STRING * 20
  407.            FirstName AS STRING * 15
  408.          END TYPE
  409.          COMMON Filename() AS Namerec
  410.          PRINT Filename(1).LastName, Filename(1).FirstName
  411.  
  412. ----------------------------------------------------------------------------
  413. Sample program #2. Demonstrates problem with long integers in subprograms.
  414.  
  415. DECLARE SUB TestLong (LongArray&())
  416. 'Demonstration to show difference between return values of long int
  417. '
  418. 'Returns desired value if compiled in the env but not if compiled by BC
  419. '
  420. 'This fault only appears if the code is in a subprogram and compiled with BC
  421. REM $Dynamic
  422. DIM LongArray&(10)
  423. DIM MainArray%(10)
  424.  
  425. CLS
  426. LongArray&(1) = 100
  427. MainArray%(1) = 10
  428.  
  429. FOR x% = 1 TO 2
  430.     LongArray&(1) = MainArray%(1) + LongArray&(1)
  431. NEXT
  432.  
  433. PRINT "TestLong should = 120"
  434. PRINT "Long Array from MAIN = "; LongArray&(1)
  435. PRINT : PRINT "Same code in a subprogram"
  436. PRINT
  437.  
  438. CALL TestLong(LongArray&())
  439.  
  440. PRINT "TestLong should return 120"
  441. PRINT "Long Array from TestLong sub = "; LongArray&(1)
  442.  
  443. SUB TestLong (LongArray&())
  444. DIM IntArray%(10)
  445.  
  446. LongArray&(1) = 100
  447. IntArray%(1) = 10
  448.  
  449. FOR x% = 1 TO 2
  450.     LongArray&(1) = IntArray%(1) + LongArray&(1)
  451. NEXT
  452. END SUB
  453.  
  454.